import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;


public class Parse {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		FileInputStream file = null;
		InputStreamReader inputStreamReader = null;
		

		BufferedReader input = null;
		TreeMap<String, Integer> termMap = new TreeMap<String, Integer>();
		try {
			file = new FileInputStream("dic/199801.txt");
			inputStreamReader = new InputStreamReader(file, "GBK");
			input = new BufferedReader(inputStreamReader);
			File outputFile = new File("dic/tmp.txt");
			Writer write = new FileWriter(outputFile);

			String str = null;
			String[] tmp1 = null;
			String[] tmp2 = new String[2];
			int count = 0;
			
			while((str = input.readLine()) != null )
			{
				tmp1 = str.split("  ");
				for(int i=0,j=1; j<tmp1.length; ++i, ++j)
				{
					String s1,s2;
					s1 = tmp1[i].substring(tmp1[i].indexOf("/")+1, tmp1[i].length());
					s2 = tmp1[j].substring(tmp1[j].indexOf("/")+1, tmp1[j].length());
					if(termMap.containsKey(s1+","+s2))
					{
						int value = termMap.get(s1+","+s2);
						value++;
						termMap.put(s1+","+s2, value);
					}
					else {
						termMap.put(s1+","+s2, 1);
					}
					count++;
				}
			}
			
			Set<Map.Entry<String, Integer>> entrySet = termMap.entrySet();
			
			//Iterator<Map.Entry<String, Integer>> iterator = hashSet.iterator();
			
			for(Map.Entry<String, Integer> entry : entrySet)
			{
				Double prob = (double)entry.getValue()/count;
				write.write(entry.getKey()+","+prob.+","+entry.getValue()+"\n");
			}
			write.write(count);
			outputFile.createNewFile();
			write.close();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

}
